import { ContentTypeEnum } from '@/enums/httpEnum';
import { defHttp } from '@/utils/http/axios';
import { CreateInterfaceParams, UpdateInterfaceParams, InterfaceParams } from './model/systemModel';

enum Api {
  Interface = '/interface/',
  List = '/interface/list',
  GetAll = '/interface/list/all',
}

/**
 * 创建接口
 * @params CreateInterfaceParams
 * @returns Promise
 */
export const addInterface = (params?: CreateInterfaceParams) =>
  defHttp.post(
    {
      url: Api.Interface,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA, PermsCode: 'interface:create' },
      params: params,
    },
    { isTransformResponse: false },
  );

/**
 * 更新接口
 * @param id
 * @param params
 * @returns
 */
export const updateInterface = (id: Number, params?: UpdateInterfaceParams) =>
  defHttp.post(
    {
      url: `${Api.Interface}/${id}`,
      params: params,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    },
    { isTransformResponse: false },
  );

/**
 * 接口列表
 * @param params InterfaceParams
 * @returns
 */
export const getInterfaceList = (params?: InterfaceParams) =>
  defHttp.get({ url: Api.List, params: params });

/**
 * 删除接口
 * @param ids
 * @returns
 */
export const deleteInterfaceIds = (ids: string) =>
  defHttp.delete<any>(
    {
      url: `${Api.Interface}${ids}`,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
      params: { ids },
    },
    { isTransformResponse: false },
  );

export const getAll = () => defHttp.get({ url: Api.GetAll });
